Micron Document
Livres et Wikis | Archives | Info


JavaScript syntax
part 10/43 Β· 161.3 KB total
layout: Wide Β· Narrow Β· Centered
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
NaN; // The Not-A-Number value, also returned as a failure in ...
// ... string-to-number conversions

Infinity and NaN are numbers:

typeof Infinity; // returns "number"
typeof NaN; // returns "number"

These three special values correspond and behave as the IEEE-754
describes them.

The Number constructor (used as a function), or a unary + or -, may be
used to perform explicit numeric conversion:

const myString = "123.456";
const myNumber1 = Number(myString);
const myNumber2 = +myString;

When used as a constructor, a numeric wrapper object is created (though
it is of little use):

const myNumericWrapper = new Number(123.456);

However, NaN is not equal to itself:

const nan = NaN;
console.log(NaN == NaN); // false
console.log(NaN === NaN); // false
console.log(NaN !== NaN); // true
console.log(nan !== nan); // true
// Users can use the isNaN methods to check for NaN
console.log(isNaN("converted to NaN")); // true
console.log(isNaN(NaN)); // true
console.log(Number.isNaN("not converted")); // false
console.log(Number.isNaN(NaN)); // true

BigInt

In JavaScript, regular numbers are represented with the IEEE 754
floating point type, meaning integers can only safely be stored if the
value falls between Number.MIN_SAFE_INTEGER and Number.MAX_SAFE_INTEGER.
cite-ref-10[10] BigInts instead represent integers of any size, allowing
programmers to store integers too high or low to be represented with the
IEEE 754 format.cite-ref-bigint-mdn-11-0[11]

There are two ways to declare a BigInt value. An n can be appended to an
integer, or the BigInt function can be used:cite-ref-bigint-mdn-11-1[11]

const a = 12345n; // Creates a variable and stores a BigInt value of
12345
const b = BigInt(12345);

String

A string in JavaScript is a sequence of characters. In JavaScript,
strings can be created directly (as literals) by placing the series of
characters between double (") or single (') quotes. Such strings must be
written on a single line, but may include escaped newline characters
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────